/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/




#if !defined(AFX_PGLMOUSE_H__338966CD_1C93_11D4_8D89_00409503B978__INCLUDED_)
#define AFX_PGLMOUSE_H__338966CD_1C93_11D4_8D89_00409503B978__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/*!\brief A mouse handler.

  Takes care of handling the mouse moves or pressed buttons.
  \ingroup PGLGroup
*/
class PGLMFC_EXT_CLASS CPGLMouse  
{
public:
	//!  \name Constructors
	//@{
	/// default constructor
	CPGLMouse();
	/// destructor
	~CPGLMouse(){};
	//@}

	//! \name Pressing button down
	//@{
	/// the left button has been pressed at position x,y
	void LeftBtnPressed(int x,int y)		{ m_iCLBx=m_iLBx=x; m_iCLBy=m_iLBy=y; m_bLDown=TRUE;};
	/// the right button has been pressed at position x,y
	void RightBtnPressed(int x,int y)		{ m_iCRBx=m_iRBx=x; m_iCRBy=m_iRBy=y; m_bRDown=TRUE;};
	/// the left button has been released
	void LeftBtnReleased()		{ m_bLDown=FALSE; };
	/// the left button has been released
	void RightBtnReleased()	{ m_bRDown=FALSE;};
	//@}

	//! \name Button pressed state
	//@{
	//! returns true if left button down. In that case, _x,_y is the last mouse position
	bool IsLeftBtnDown(int& _x,int &_y)		{ if (m_bLDown) {_x=m_iLBx; _y=m_iLBy;} return m_bLDown;};
	//! returns true if right button down. In that case, _x,_y is the last mouse position
	bool IsRightBtnDown(int& _x,int &_y)	{ if (m_bRDown) {_x=m_iRBx; _y=m_iRBy;} return m_bRDown;};
	//@}

	//! \name Last position getters
	//@{
	//! Sets _x, _y as the last mouse position with left button down
	void GetLeftLastPos(int& _x, int& _y) const		{ _x=m_iLBx; _y=m_iLBy;};
	//! Sets _x, _y as the last mouse position with right button down
	void GetRightLastPos(int& _x, int& _y) const	{ _x=m_iRBx; _y=m_iRBy;};
	//! Sets _x, _y as the mouse position when the left button was clicked
	void GetLeftFirstPos(int& _x, int& _y) const	{ _x=m_iCLBx; _y=m_iCLBy;};
	//! Sets _x, _y as the mouse position when the right button was clicked
	void GetRightFirstPos(int& _x, int& _y) const	{ _x=m_iCRBx; _y=m_iCRBy;};
	//@}

	//! \name Update position
	//@{
	void Move(int x, int y)					{ UpdateLeftPos(x,y); UpdateRightPos(x,y);};
	void UpdateLeftPos(int _x, int _y)		{ m_iLBx=_x; m_iLBy=_y;};
	void UpdateRightPos(int _x, int _y)		{ m_iRBx=_x; m_iRBy=_y;};
	//@}

	//! \name Moving state getters
	//@{
	//! Mouse is moving, left button down
	void LeftMove() { m_bLMoving=true;};
	//! Mouse is moving, right button down
	void RightMove() { m_bLMoving=true;};
	//! Resest move bit
	void Stop() { m_bLMoving=m_bRMoving=FALSE;};
	//! Returns true if mouse if moving and left button is down
	bool IsLeftMoving() const {return (m_bLMoving && m_bLDown);};
	//! Returns true if mouse if moving and right button is down
	bool IsRightMoving() const {return (m_bLMoving && m_bRDown);};
	//@}

protected:
	//! \name Attributes
	//@{
	//! x position of the pointer when the left button was clicked
	int m_iCLBx;
	//! y position of the pointer when the left button was clicked
	int m_iCLBy;
	//! x position of the pointer when the right button was clicked
	int m_iCRBx;
	//! y position of the pointer when the right button was clicked
	int m_iCRBy;
	//! x last position of the pointer
	int m_iLBx;
	//! y last position of the pointer
	int m_iLBy;
	//! x position of the pointer
	int m_iRBx;
	//! y position of the pointer
	int m_iRBy;
	//! true if left button pressed
	bool m_bLDown;
	//! true if right button pressed
	bool m_bRDown;
	//! true if mouse moving with left button down
	bool m_bLMoving;
	//! true if mouse moving with left button down
	bool m_bRMoving;
	//@}
};

#endif // !defined(AFX_MOUSECLASS_H__338966CD_1C93_11D4_8D89_00409503B978__INCLUDED_)
